package com.eleadmin.order.controller;

import com.eleadmin.common.core.web.*;
import com.eleadmin.common.core.annotation.OperationLog;
import com.eleadmin.damon.utils.results.PageResult2;
import com.eleadmin.order.entity.ContainerBillProcess;
import com.eleadmin.order.service.ContainerBillProcessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;


/**
 *
 * 订单流程状态
 * @author : Doman
 * @date : 2023-04-03 14:36:45
 * @version ：1.0
 */

@Api(tags = "订单流程状态")
@RestController
@RequestMapping("/api/order/containerBillProcess")
public class ContainerBillProcessController extends BaseController {

    @Autowired
    private ContainerBillProcessService containerBillProcessService;

    @PreAuthorize("hasAuthority('order:containerBillProcess:list')")
    @ApiOperation("分页查询订单流程状态")
    @GetMapping("/page")
    public JsonResult page(PageResult2<T> page, ContainerBillProcess containerBillProcess) throws Exception{
        return containerBillProcessService.list(page, containerBillProcess, getLoginUser());
    }

    @PreAuthorize("hasAuthority('order:containerBillProcess:list')")
    @ApiOperation("查询全部订单流程状态")
    @GetMapping()
    public JsonResult list(ContainerBillProcess containerBillProcess){
        return containerBillProcessService.list(containerBillProcess, getLoginUser());
    }

    @PreAuthorize("hasAuthority('order:containerBillProcess:list')")
    @ApiOperation("根据id查询订单流程状态")
    @GetMapping("/{id}")
    public JsonResult get(@PathVariable("id") String id) {
        return containerBillProcessService.getById(id);
    }


    @PreAuthorize("hasAuthority('order:containerBillProcess:save')")
    @OperationLog
    @ApiOperation(value ="添加订单流程状态")
    @PostMapping()
    public JsonResult save(@RequestBody ContainerBillProcess containerBillProcess) {
        try {
            return containerBillProcessService.save(containerBillProcess, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }

    }

    @PreAuthorize("hasAuthority('order:containerBillProcess:update')")
    @OperationLog
    @ApiOperation(value ="修改订单流程状态")
    @PutMapping()
    public JsonResult update(@RequestBody ContainerBillProcess containerBillProcess) {
        try {
            return containerBillProcessService.update(containerBillProcess, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

    @PreAuthorize("hasAuthority('order:containerBillProcess:remove')")
    @OperationLog
    @ApiOperation(value ="删除订单流程状态")
    @DeleteMapping("/{id}")
    public JsonResult remove(@PathVariable("id") String id) {
        try {
            return containerBillProcessService.remove(id, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

}
